#!/bin/sh

ARTIFACTS="lwjgl lwjgl_util jinput"
VERSION=$1

if [ -z "$VERSION" ]; then
    echo "Usage: $0 version (e.g. 2.6)"
    exit 255
fi

if [ ! -f lwjgl-$VERSION.zip ]; then
    echo "lwjgl-$VERSION.zip must be in the current directory."
    exit 255
fi

unzip lwjgl-$VERSION.zip

sed "s:VERSION:$VERSION:g" lwjgl_parent.pom.xml > tmp.pom
mvn deploy:deploy-file -DrepositoryId=lwjgl-maven -Durl=file:repository \
    -DpomFile=tmp.pom -Dfile=tmp.pom
rm tmp.pom

for ARTIFACT in $ARTIFACTS; do
    sed "s:VERSION:$VERSION:g" $ARTIFACT.pom.xml > tmp.pom
    mvn deploy:deploy-file -DrepositoryId=lwjgl-maven -Durl=file:repository \
        -DpomFile=tmp.pom -Dfile=lwjgl-$VERSION/jar/$ARTIFACT.jar
    rm tmp.pom
done

OSES="linux macosx windows solaris"
for OS in $OSES; do
    cd lwjgl-$VERSION/native/$OS
    jar cf ../../../lwjgl-native-$OS.jar *
    cd ../../..
    sed "s:VERSION:$VERSION:g" lwjgl-native-$OS.pom.xml > tmp.pom
    mvn deploy:deploy-file -DrepositoryId=lwjgl-maven -Durl=file:repository \
        -DpomFile=tmp.pom -Dfile=lwjgl-native-$OS.jar
    rm lwjgl-native-$OS.jar tmp.pom
done

rm -rf lwjgl-$VERSION
